package cn.iocoder.yudao.module.dine.desk.controller.admin;

import cn.iocoder.yudao.framework.business.basic.annotation.AdminJsonView;
import cn.iocoder.yudao.framework.business.basic.controller.CrudController;
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.module.dine.desk.pojo.dto.DeskCategoryQueryDTO;
import cn.iocoder.yudao.module.dine.desk.pojo.dto.DeskCategorySaveDTO;
import cn.iocoder.yudao.module.dine.desk.pojo.vo.DeskCategoryVO;
import cn.iocoder.yudao.module.dine.desk.service.DeskCategoryService;
import com.fasterxml.jackson.annotation.JsonView;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.annotation.security.PermitAll;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <pre>
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * 前端控制器
 * OOoO0OOoO0OOOooo0oOOOO0OOOOO0oooOO0ooOOO0Ooooo0OOOOo0ooooO0OOooo0Ooooo0OOOOO
 * </pre>
 *
 * @author 山野羡民（1032694760@qq.com）
 * @since 2025/04/11
 */
@Tag(name = "管理后台 - 餐桌种类")
@RestController
@RequestMapping("/dine/desk/category")
public class DeskCategoryController implements CrudController<DeskCategoryVO, DeskCategorySaveDTO, DeskCategoryQueryDTO> {
    @Resource
    private DeskCategoryService deskCategoryService;

    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin', 'shop_admin')")
    @JsonView(AdminJsonView.class)
    @Override
    public CommonResult<DeskCategoryVO> getDetail(Long id) {
        return CommonResult.success(deskCategoryService.getDetail(id));
    }

    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin', 'shop_admin')")
    @JsonView(AdminJsonView.class)
    @Override
    public CommonResult<PageResult<DeskCategoryVO>> getPage(Integer pageNo, Integer pageSize, DeskCategoryQueryDTO param) {
        return CommonResult.success(deskCategoryService.getPage(pageNo, pageSize, param));
    }

    @PermitAll
    @JsonView(AdminJsonView.class)
    @Operation(summary = "列表")
    @GetMapping("/all")
    public CommonResult<List<DeskCategoryVO>> getEnabledAll(@RequestParam(value = "shopId", required = false) Long shopId) {
        return CommonResult.success(deskCategoryService.getEnabledAll(shopId));
    }

    @PreAuthorize("@ss.hasRole('shop_admin')")
    @Override
    public CommonResult<Long> create(DeskCategorySaveDTO param) {
        return CommonResult.success(deskCategoryService.create(param));
    }

    @PreAuthorize("@ss.hasRole('shop_admin')")
    @Override
    public CommonResult<Boolean> delete(Long id) {
        return CommonResult.success(deskCategoryService.delete(id));
    }

    @PreAuthorize("@ss.hasAnyRoles('super_admin', 'platform_admin', 'tenant_admin', 'shop_admin')")
    @Override
    public CommonResult<Boolean> update(DeskCategorySaveDTO param) {
        return CommonResult.success(deskCategoryService.update(param));
    }

}
